package wodegua.d20_collections_test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Room {
    List<Card> allCards = new ArrayList<>();
    public Room() {
        String[] names = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
        String[] colors = {"♠","♥","♣","♦"};

        int size = 0;
        //生成扑克
        for (String name : names) {
            size++;
            for (String color : colors) {
                Card c = new Card(name,color,size);
                allCards.add(c);
            }
        }
        Card c1 = new Card("","🤡",++size);
        Card c2 = new Card("","🃏",++size);
        Collections.addAll(allCards,c1,c2);
        System.out.println("新牌：" + allCards);
        Collections.shuffle(allCards);
        System.out.println("洗牌：" + allCards);
    }

    public void start() {
        List<Card> lhc = new ArrayList<>();
        List<Card> jmz = new ArrayList<>();
        List<Card> ryy = new ArrayList<>();
        for (int i = 0; i < allCards.size() - 3; i++) {
            if (i%3 == 0) {
                lhc.add(allCards.get(i));
            } else if (i%3 == 1) {
                jmz.add(allCards.get(i));
            } else if (i%3 == 2) {
                ryy.add(allCards.get(i));
            }
        }
        sortCard(lhc);
        sortCard(jmz);
        sortCard(ryy);
        List<Card> lastThree = allCards.subList(allCards.size() - 3,allCards.size());

        System.out.println("------------------------------");
        System.out.println("啊冲"+lhc);
        System.out.println("啊鸠"+jmz);
        System.out.println("啊盈"+ryy);
        System.out.println("底牌"+lastThree);
        jmz.addAll(lastThree);
        sortCard(jmz);
        System.out.println("啊鸠抢到地主后"+jmz);
    }

    private void sortCard(List<Card> card) {
//        Collections.sort(card, new Comparator<Card>() {
//            @Override
//            public int compare(Card o1, Card o2) {
//                return o1.getNumber() - o2.getNumber();
//            }
//        });
//        Collections.sort(card, (Card o1, Card o2) -> {
//                return o1.getNumber() - o2.getNumber();
//            }
//        );
        Collections.sort(card, Comparator.comparingInt(Card::getNumber));
    }
}
